home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / scripts / control / dare.m < prev    next >
Text File  |  1996-07-15  |  3KB  |  116 lines

  1. ## Copyright (C) 1996 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## Usage: x = dare (a, b, c, r {,opt})
  21. ##
  22. ## Solves discrete-time algebraic riccati equation
  23. ##
  24. ##   a' x a - x + a' x b (r + b' x b)^{-1} b' x a + c = 0
  25. ##
  26. ## for
  27. ##
  28. ##   a: nxn
  29. ##   b: nxm
  30. ##   c: nxn, symmetric positive semidefinite
  31. ##   r: mxm, invertible
  32. ##
  33. ## If c is not square, then the function attempts to use c'*c instead.
  34. ##
  35. ## Solution method: Laub's Schur method (IEEE Trans Auto Contr, 1979) applied
  36. ## to the appropriate symplectic matrix.
  37. ##
  38. ## See also: Ran and Rodman, "Stable Hermitian Solutions of Discrete
  39. ## Algebraic Riccati Equations," Mathematics of Control, Signals and
  40. ## Systems, Vol 5, no 2 (1992)  pp 165-194.
  41. ##
  42. ## opt is an option passed to the eigenvalue balancing routine default
  43. ## is "B".
  44. ##
  45. ## See also: balance, are
  46.  
  47. ## Author: A. S. Hodel <scotte@eng.auburn.edu>
  48. ## Created: August 1993
  49. ## Adapted-By: jwe
  50.  
  51. function x = dare (a, b, c, r, opt)
  52.  
  53.   if (nargin == 4 || nargin == 5)
  54.     if (nargin == 5)
  55.       if (opt != "N" || opt != "P" || opt != "S" || opt != "B")
  56.     warning ("dare: opt has an invalid value -- setting to B");
  57.     opt = "B";
  58.       endif
  59.     else
  60.       opt = "B";
  61.     endif
  62.  
  63.     ## Check a matrix dimensions
  64.     if ((n = is_square (a)) == 0)
  65.       error ("dare: a is not square");
  66.     endif
  67.  
  68.     ## Check a,b compatibility.
  69.  
  70.     [n1, m] = size (b);
  71.  
  72.     if (n1 != n)
  73.       warning ("dare: a,b are not conformable");
  74.     endif
  75.  
  76.     if (is_controllable (a, b) == 0)
  77.       warning ("dare: a,b are not controllable");
  78.     endif
  79.  
  80.     ## Check a,c compatibility.
  81.  
  82.     if (is_observable (a, c) == 0)
  83.       warning ("dare: a,c are not observable");
  84.     endif
  85.  
  86.     if ((p = is_square (c)) == 0)
  87.       c = c'*c;
  88.       p = rows (c);
  89.     endif
  90.  
  91.     if (n != p)
  92.       error ("dare: a,c are not conformable");
  93.     endif
  94.  
  95.     ## Check r dimensions.
  96.  
  97.     if ((m1 = is_square (r)) == 0)
  98.       warning ("dare: r is not square");
  99.     elseif (m1 != m)
  100.       warning ("b,r are not conformable");
  101.     endif
  102.  
  103.     brb = (b/r)*b';
  104.     atc = a'\c;
  105.     [d, sy] = balance ([a + brb*atc, -brb/(a'); -atc, (inv (a'))], opt);
  106.     [u, s] = schur (sy, 'D');
  107.     u = d*u;
  108.     n1 = n+1;
  109.     n2 = 2*n;
  110.     x = u (n1:n2, 1:n)/u(1:n, 1:n);
  111.   else
  112.     usage ("x = dare (a, b, c, r {,opt})");
  113.   endif
  114.  
  115. endfunction
  116.